package com.tianqu.tms.entity;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dao.TmsDetectInfoDao;
import com.tianqu.tms.dao.TmsDetectNormalDao;
import com.tianqu.tms.dao.TmsDetectPicDao;
import com.tianqu.tms.dao.TmsDetectSeniorDao;
import com.tianqu.tms.dao.ViewListDao;
import com.tianqu.tms.dto.TmsDetectInfoDto;

/**
 * 车辆管理entity
 * 
 * @author tianshifu
 * 
 */
public class TmsDetectInfo extends ViewListManager {
	private static final long serialVersionUID = 1L;

	public static final int ALLOCATE_CARINFO = 1;// 待分配

	public static final int WAIT_DETECT_TIS = 2;// 待检测（IPAD）服务器端

	public static final int TOBE_DETECT_CARINFO = 3;// 待检测（人工）

	public static final int WAIT_DETECT_IPAD = 4;// 待检测（IPAD）客户端

	public static final int WAIT_TOBE_CONFIRMED = 5;// 待确认(客户端)

	public static final int DETECT_DATA_EXPORT = 6;// 数据导出CSV

	private String carSerial;// 车辆ID
	private String carName;// 车辆名称
	private String carLicense;// 车牌号码
	private String regDate;// 登记日期
	private String carCheckInsur;// 年检日期
	private String trafficInsur;// 交强险日期
	private int exhaust;// 排气量
	private int mileage;// 行驶里程
	private int TQcarNum;// 车辆数量
	private int TASNum;// 车辆数量
	private String color;// 颜色
	private int gearbox;// 变速箱
	private int fuelDict;// 燃油方式
	private int nature;// 使用性质
	private int counts;// 车辆信息条数
	private int source;// 来源
	private int status;// 车辆状态
	private String updateTime; // 修改时间
	private int updateUser = 1;// 修改者
	private String totalScore;// 总评
	private String externalScore;// 外装
	private String internalScore;// 内饰

	private String addModeName;// 3转ipad 2转人工
	private int chkModel = 0;// 检测模式 1 普通检测 2高级检测
	private int carDetectId = 0;// 检测报告关联ID

	/** 车辆八大配置 **/
	private int skylight;
	private int leatherSeats;
	private int aluminumRim;
	private int gpsNavigation;
	private int autoWindow;
	private int abs;
	private int srsNumber;
	private int fourWheelDrive;
	/*************************/
	private int troubleCar;// 事故车 1是u 2不是
	private String carDescribe;// 车况描述

	/********* 高级搜索条件 **********/
	private String startSerial;// 起始车辆ID

	private String endSerial;// 结束车辆ID

	private String startTime;// 起始受理时间

	private String endTime;// 受理时间止

	private int scopeNum;// 页面序号，目前只有高级搜索有序号

	private int seeBsflag;// 用于改变页面样式
    private Timestamp checkTime;
	
    private int bidStatus;//竞价状态
    
	public static TmsDetectInfo getInstance() {
		TmsDetectInfo carInfo = new TmsDetectInfo();
		carInfo.setExisting(false);
		return carInfo;
	}

	/**
	 * 查询出待分配来源和条数
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public List<TmsDetectInfo> getCarInfoSourseAndCountsByStatus(int status)
			throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);
		List<TmsDetectInfoDto> carInfoList = carInfoDao
				.getAllocateDispatchInfo(status);
		List<TmsDetectInfo> entityList = new ArrayList<TmsDetectInfo>();
		if (carInfoList != null) {
			for (int i = 0; i < carInfoList.size(); i++) {
				TmsDetectInfoDto dto = (TmsDetectInfoDto) carInfoList.get(i);
				TmsDetectInfo entity = new TmsDetectInfo();
				entity.setCounts(dto.getCounts());
				entityList.add(entity);
			}
		}

		return entityList;
	}

	/**
	 * 根据车辆ID查询车辆基本信息
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public TmsDetectInfoDto getAllocateInfoById(String carSerial)
			throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);

		TmsDetectInfoDto dto = carInfoDao.getAllocateCarInfoById(carSerial,1);

		return dto;
	}

	/**
	 * 根据车辆ID查询车辆基本信息 待检测（IPAD详细页）
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public TmsDetectInfo getWDIpadCarInfoBySerial(String carSerial,int status)
			throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);

		TmsDetectInfo entity = new TmsDetectInfo();

		TmsDetectInfoDto dto = carInfoDao.getAllocateCarInfoById(carSerial,status);

		setEntityFromDto(entity, dto, 1, 1);

		return entity;
	}

	/**
	 * ' 根据车辆来源查询车辆基本信息列表(带分页)
	 * 
	 * @return
	 * @throws TmsDaoException
	 */

	public List<TmsDetectInfo> getAllocationCarInfoBySource(String serial,
			int status) throws TmsDaoException {

		TmsDetectInfoDao carDao = (TmsDetectInfoDao) TmsDao.getInstance(
				TmsDao.TMS_DECT_CAR_INFO, getPageNo(), getMaxIndex(),
				getSortKey(), isAsc());
		ViewListDao idao = (ViewListDao) TmsDao.getViewListDao((TmsDao) carDao,
				TmsDao.TMS_DECT_CAR_INFO);

		List<TmsDetectInfoDto> list = carDao.getAllocateDispatchInfoBySource(
				serial, status);
		TmsDetectInfo entity = null;
		List<TmsDetectInfo> entityList = new ArrayList<TmsDetectInfo>();
		int pp = 1;
		if (list != null) {
			for (int i = 0; i < list.size(); i++) {
				TmsDetectInfoDto dto = (TmsDetectInfoDto) list.get(i);
				entity = new TmsDetectInfo();
				entity = setEntityFromDto(entity, dto, pp, idao.getPageNo());
				entityList.add(entity);
				pp++;
			}
		}

		setPagingInfo(idao);
		return entityList;
	}

	/**
	 * ' 根据车辆来源查询车辆基本信息列表(带分页)待检测人工
	 * 
	 * @return
	 * @throws TmsDaoException
	 */

	public List<TmsDetectInfo> getWDPersonCarInfoBySource(int source, int status)
			throws TmsDaoException {

		TmsDetectInfoDao carDao = (TmsDetectInfoDao) TmsDao.getInstance(
				TmsDao.TMS_DECT_CAR_INFO, getPageNo(), getMaxIndex(),
				getSortKey(), isAsc());
		ViewListDao idao = (ViewListDao) TmsDao.getViewListDao((TmsDao) carDao,
				TmsDao.TMS_DECT_CAR_INFO);

		List<TmsDetectInfoDto> list = carDao.getWDPersonDispatchInfoBySource(
				source, status);
		TmsDetectInfo entity = null;
		List<TmsDetectInfo> entityList = new ArrayList<TmsDetectInfo>();
		if (list != null) {
			int pp = 1;
			for (int i = 0; i < list.size(); i++) {
				TmsDetectInfoDto dto = (TmsDetectInfoDto) list.get(i);
				entity = new TmsDetectInfo();
				entity = setEntityFromDto(entity, dto, pp, idao.getPageNo());
				entityList.add(entity);
			}
		}

		setPagingInfo(idao);
		return entityList;
	}

	/**
	 * 将dto数据set到entity中
	 */
	public TmsDetectInfo setEntityFromDto(TmsDetectInfo entity,
			TmsDetectInfoDto dto, int pp, int pageNo) {
		entity.setCarSerial(dto.getCarSerial());
		entity.setCarDetectId(dto.getCarDetectId());// 检测ID
		entity.setCarName(dto.getCarName());
		entity.setCarLicense(dto.getCarLicense());
		entity.setRegDate(dto.getRegDate());
		entity.setCarCheckInsur(dto.getCarCheckInsur());
		entity.setTrafficInsur(dto.getTrafficInsur());
		entity.setExhaust(dto.getExhaust());
		entity.setColor(dto.getColor());
		entity.setGearbox(dto.getGearbox());
		entity.setFuelDict(dto.getFuelDict());
		entity.setNature(dto.getNature());
		entity.setUpdateTime(StringUtil.getTimeByTimeStamp(dto.getUpdateTime()));
		entity.setSource(dto.getSource());
		entity.setChkModel(dto.getChkModel());
		entity.setStatus(dto.getStatus());
		entity.setTotalScore(dto.getTotalScore());
		entity.setExternalScore(dto.getExternalScore());
		entity.setInternalScore(dto.getInternalScore());
		entity.setChkModel(dto.getChkModel());
		entity.setCarDetectId(dto.getCarDetectId());
		entity.setTotalScore(dto.getTotalScore());// 总评
		entity.setExternalScore(dto.getExternalScore());// 外装
		entity.setInternalScore(dto.getInternalScore());// 内饰
		entity.setMileage(dto.getMileage());
		// 八大配置
		entity.setSkylight(dto.getSkylight());
		entity.setLeatherSeats(dto.getLeatherSeats());
		entity.setAluminumRim(dto.getAluminumRim());
		entity.setGpsNavigation(dto.getGpsNavigation());
		entity.setAutoWindow(dto.getAutoWindow());
		entity.setAbs(dto.getAbs());
		entity.setSrsNumber(dto.getSrsNumber());
		entity.setFourWheelDrive(dto.getFourWheelDrive());
		entity.setCarDescribe(dto.getCarDescribe());
		entity.setSeeBsflag(dto.getSeeParam());
		// 页面的序号
		entity.setScopeNum((pageNo - 1) * 10 + pp);
		
		entity.setBidStatus(dto.getBidStatus());

		return entity;
	}

	/**
	 * CSV车辆基本数据插入
	 * 
	 * @return
	 */
	public void carImportcsv(TmsDetectInfo csv) throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);
		TmsDetectInfoDto dto = new TmsDetectInfoDto();
		dto.setCarSerial(csv.getCarSerial());
		dto.setCarName(csv.getCarName());
		dto.setCarLicense(csv.getCarLicense());
		dto.setRegDate(csv.getRegDate());
		dto.setCarCheckInsur(csv.getCarCheckInsur());
		dto.setTrafficInsur(csv.getTrafficInsur());
		dto.setExhaust(csv.getExhaust());
		dto.setColor(csv.getColor());
		dto.setGearbox(csv.getGearbox());
		dto.setFuelDict(csv.getFuelDict());
		dto.setNature(csv.getNature());
		dto.setSource(csv.getSource());
		dto.setStatus(csv.getStatus());
		dto.setUpdateUser(csv.getUpdateUser());
		carInfoDao.carImportcsv(dto);
	}

	/**
	 * 删除车辆信息表
	 * 
	 * @throws TmsDaoException
	 */
	public void delCarinfo(TmsDetectInfo csv) throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);
		// deleteDectInfoBySerialCollection("("+csv.getCarSerial()+")",carInfoDao);//删除检测报告和图片信息
		carInfoDao.delCarinfo(csv.getCarSerial());
	}

	/**
	 * 根据车辆ID查询车辆信息
	 * 
	 * 传过来一个车辆ID数组
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public List<TmsDetectInfo> findAllocateInfoByCheckbox(String[] carSerial,
			String addMode) throws TmsDaoException {
		List<TmsDetectInfo> entityList = new ArrayList<TmsDetectInfo>();
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);
		String carModeNameStr = "";
		if (addMode.equals("2")) {
			carModeNameStr = "IPAD";// ipad
		}
		if (addMode.equals("3")) {
			carModeNameStr = "人工";// 人工
		}

		// 解析数组
		String serialStr = "";
		if (carSerial != null) {
			for (int i = 0; i < carSerial.length; i++) {
				serialStr += carSerial[i] + ",";
			}

			serialStr = "(" + serialStr.substring(0, serialStr.length() - 1)
					+ ")";// 一个车辆ID集合的字符串
		}

		List<TmsDetectInfoDto> dtoList = carInfoDao
				.findAllocateCarInfoBySerialCollection(serialStr);// 根据车辆ID集合获取车辆信息
		TmsDetectInfo entity = null;
		if (dtoList != null) {
			for (int i = 0; i < dtoList.size(); i++) {
				TmsDetectInfoDto dto = (TmsDetectInfoDto) dtoList.get(i);
				entity = new TmsDetectInfo();
				entity.setAddModeName(carModeNameStr);// 将检测名set到entity中
				entity = setEntityFromDto(entity, dto, 1, 1);
				entityList.add(entity);
			}
		}

		return entityList;
	}

	/**
	 * 查询车辆数量
	 * 
	 * @param source
	 * @param carType
	 * @return num
	 * @throws TmsDaoException
	 */
	public int getcarNum(int source, int carType) throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);
		return carInfoDao.getcarNum(source, carType);
	}

	/**
	 * 根据车辆ID集合和录入模式批量更新数据库
	 * 
	 * 实现车辆检测录入方式分配
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public void updateCarInfoBySerialCollectionAndAddMode(String[] carSerial,
			String addMode, int userId) throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao.getInstance(TmsDao.TMS_DECT_CAR_INFO);

		// 解析数组
		String serialStr = "";
		if (carSerial != null) {
			for (int i = 0; i < carSerial.length; i++) {
				if(!carSerial[i].equals("false"))
				{
					serialStr += carSerial[i] + ",";
				}
			}

			serialStr = "(" + serialStr.substring(0, serialStr.length() - 1)
					+ ")";// 一个车辆ID集合的字符串
		}

		
		carInfoDao.updateCarInfoBySerialCollectionAndAddMode(serialStr,
				addMode, userId);// 更新
	}

	/**
	 * 用于删除信息的公共方法 先删图片 再删检测信息 在还原基本信息表
	 * 
	 * @throws TmsDaoException
	 * 
	 */
	public void deleteDectInfoBySerialCollection(String[] carSerial) throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao.getInstance(TmsDao.TMS_DECT_CAR_INFO);
		TmsDetectNormalDao normalDao = (TmsDetectNormalDao) TmsDao.getInstance(TmsDao.TMS_DETECT_NORMAL);// 普通检测
		TmsDetectSeniorDao seniorDao = (TmsDetectSeniorDao) TmsDao.getInstance(TmsDao.TMS_DETECT_SENIOR);// 高级检测
		TmsDetectPicDao detectPicDao = (TmsDetectPicDao) TmsDao.getInstance(TmsDao.TMS_DETECT_PIC);// 车辆检测图片
		// 车辆ID和检测模式批量删除检测报告和初始化车辆信息表
		// 根据车辆ID查询所有检测信息
		// 解析数组
		String serialStr = "";
		if (carSerial != null) {
			for (int i = 0; i < carSerial.length; i++) {
				if(!carSerial[i].equals("false"))
				{
					serialStr += carSerial[i] + ",";
				}
			}

			serialStr = "(" + serialStr.substring(0, serialStr.length() - 1)+ ")";// 一个车辆ID集合的字符串
		}
		List<TmsDetectInfoDto> dtoList = carInfoDao.findAllocateCarInfoBySerialCollection(serialStr);
		if (dtoList.size()>0) {
			for (int i = 0; i < dtoList.size(); i++) {
				TmsDetectInfoDto dto = (TmsDetectInfoDto) dtoList.get(i);
				if (dto.getChkModel() == 1) {
					// 普通检测
					detectPicDao.deleteTisPicInfoByDetectId(dto.getCarDetectId());
					normalDao.delDetectNormal(dto.getCarDetectId());
//					// 更新基本信息表 将所有检测信息置空 根据车辆ID
//					carInfoDao.updateCarInfoToZeroBySerial(dto.getCarSerial());
				} else if (dto.getChkModel() == 2) {
					// 高级检测
					detectPicDao.deleteTisPicInfoByDetectId(dto.getCarDetectId());
					seniorDao.delDetectSenior(dto.getCarDetectId());
				}
			}
			// 更新基本信息表 将所有检测信息置空 根据车辆ID
			carInfoDao.updateCarInfoToZeroBySerial(serialStr);
		}
	}
	/**
	 * 
	 * 批量还原车辆检测基本信息
	 * @throws TmsDaoException 
	 * 
	 */
	public void updateCarInfoToZeroBySerial(String[] carSerial) throws TmsDaoException
	{
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao.getInstance(TmsDao.TMS_DECT_CAR_INFO);
		// 解析数组
		String serialStr = "";
		if (carSerial != null) {
			for (int i = 0; i < carSerial.length; i++) {
				serialStr += carSerial[i] + ",";
			}

			serialStr = "(" + serialStr.substring(0, serialStr.length() - 1)
					+ ")";// 一个车辆ID集合的字符串
		}
		carInfoDao.updateCarInfoToZeroBySerial(serialStr);
	}

	/**
	 * 根据车辆ID集合查询出待分配需要删除的车辆信息
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public List<TmsDetectInfo> findAllocateDeleteInfoByCheckbox(
			String[] carSerial) throws TmsDaoException {
		List<TmsDetectInfo> entityList = new ArrayList<TmsDetectInfo>();
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);

		// 解析数组
		String serialStr = "";
		if (carSerial != null) {
			for (int i = 0; i < carSerial.length; i++) {
				serialStr += carSerial[i] + ",";
			}

			serialStr = "(" + serialStr.substring(0, serialStr.length() - 1)
					+ ")";// 一个车辆ID集合的字符串
		}

		List<TmsDetectInfoDto> dtoList = carInfoDao
				.findAllocateCarInfoBySerialCollection(serialStr);// 根据车辆ID集合获取车辆信息
		TmsDetectInfo entity = null;
		if (dtoList != null) {
			for (int i = 0; i < dtoList.size(); i++) {
				TmsDetectInfoDto dto = (TmsDetectInfoDto) dtoList.get(i);
				entity = new TmsDetectInfo();
				entity = setEntityFromDto(entity, dto, 1, 1);
				entityList.add(entity);
			}
		}

		return entityList;
	}

	/**
	 * 待分配批量删除执行删除
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public void deleteCarInfoBySerialCollection(String[] carSerial)
			throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);
		// 解析数组
		String serialStr = "";
		if (carSerial != null) {
			for (int i = 0; i < carSerial.length; i++) {
				serialStr += carSerial[i] + ",";
			}

			serialStr = "(" + serialStr.substring(0, serialStr.length() - 1)
					+ ")";// 一个车辆ID集合的字符串
		}
		// deleteDectInfoBySerialCollection(serialStr,carInfoDao);//删除检测报告和图片信息
		carInfoDao.deleteCarInfoBySerialCollection(serialStr);// 删除
	}

	/**
	 * 根据车辆状态查询出所有待检测车辆信息
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public List<TmsDetectInfo> findAllWDIpadCarInfoByStatus(int status)
			throws TmsDaoException {

		TmsDetectInfoDao carDao = (TmsDetectInfoDao) TmsDao.getInstance(
				TmsDao.TMS_DECT_CAR_INFO, getPageNo(), getMaxIndex(),
				getSortKey(), isAsc());
		ViewListDao idao = (ViewListDao) TmsDao.getViewListDao((TmsDao) carDao,
				TmsDao.TMS_DECT_CAR_INFO);

		List<TmsDetectInfoDto> list = carDao
				.findAllWDIpadCarInfoByStatus(status);
		TmsDetectInfo entity = null;
		List<TmsDetectInfo> entityList = new ArrayList<TmsDetectInfo>();
		if (list != null) {
			int pp = 1;
			for (int i = 0; i < list.size(); i++) {
				TmsDetectInfoDto dto = (TmsDetectInfoDto) list.get(i);
				entity = new TmsDetectInfo();
				entity = setEntityFromDto(entity, dto, pp, idao.getPageNo());
				entityList.add(entity);
				pp++;
			}
		}

		setPagingInfo(idao);
		return entityList;
	}

	/**
	 * 根据车辆ID对车辆基本信息进行删除
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public void deleteTisCarinfoBySerial(String carSerial)
			throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);

		String carSerialSum = "(" + carSerial + ")";
		// deleteDectInfoBySerialCollection(carSerialSum,carInfoDao);//删除检测报告和图片信息
		carInfoDao.deleteCarInfoBySerialCollection(carSerialSum);// 删除
	}

	/**
	 * 更新基本信息表（普通检测报告录入）
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public void updateCarInfoByNormalDetectInfo(TmsDetectInfo entity,
			int chkModel) throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);

		TmsDetectInfoDto dto = new TmsDetectInfoDto();

		dto = setDtoFromEntity(dto, entity);
		dto.setChkModel(chkModel);

		// 执行更新
		carInfoDao.updateCarDetectInfo(dto);

	}

	/**
	 * 
	 * 更新车辆状态
	 * 
	 * @param carSerial
	 * @param status
	 * @throws TmsDaoException
	 */
	public void updateCarStatus(String carSerial, int status)
			throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);
		carInfoDao.updateCarStatus(carSerial, status);
	}

	/**
	 * 将entity信息set到dto中
	 * 
	 * @return
	 */
	private TmsDetectInfoDto setDtoFromEntity(TmsDetectInfoDto dto,
			TmsDetectInfo entity) {
		dto.setCarSerial(entity.getCarSerial());
		dto.setCarDetectId(entity.getCarDetectId());
		dto.setTotalScore(entity.getTotalScore());// 总评
		dto.setExternalScore(entity.getExternalScore());// 外装
		dto.setInternalScore(entity.getInternalScore());// 内饰
		dto.setMileage(entity.getMileage());// 行驶里程
		dto.setTroubleCar(entity.getTroubleCar());
		/********** 八大配置 ***********/
		dto.setSkylight(entity.getSkylight());
		dto.setLeatherSeats(entity.getLeatherSeats());
		dto.setAluminumRim(entity.getAluminumRim());
		dto.setGpsNavigation(entity.getGpsNavigation());
		dto.setAutoWindow(entity.getAutoWindow());
		dto.setAbs(entity.getAbs());
		dto.setSrsNumber(entity.getSrsNumber());
		dto.setFourWheelDrive(entity.getFourWheelDrive());
		dto.setCarDescribe(entity.getCarDescribe());// 车况描述
		dto.setStatus(entity.getStatus());// 车辆状态
		/**** 车辆搜索条件 ******/
		dto.setStartSerial(entity.getStartSerial());
		dto.setEndSerial(entity.getEndSerial());
		dto.setStartTime(entity.getStartTime());
		dto.setEndTime(entity.getEndTime());
		dto.setSource(entity.getSource());
		dto.setUpdateUser(entity.getUpdateUser());

		return dto;
	}

	/**
	 * 根据车辆ID和车辆状态还原基本信息表信息
	 * 
	 * 状态是用来更新的状态
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public void resetCarInfoByIdAndStatus(String carSerial, int status,
			int userId) throws TmsDaoException {
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao
				.getInstance(TmsDao.TMS_DECT_CAR_INFO);
		carInfoDao.resetCarInfoByIdAndStatus(carSerial, status, userId);

	}

	/**
	 * 
	 * 车辆搜索 根据页面传过来的查询条件查询车辆信息
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public List<TmsDetectInfo> findCarInfoByCon(TmsDetectInfo entity)
			throws TmsDaoException {
		TmsDetectInfoDao carDao = (TmsDetectInfoDao) TmsDao.getInstance(
				TmsDao.TMS_DECT_CAR_INFO, getPageNo(), getMaxIndex(),
				getSortKey(), isAsc());
		ViewListDao idao = (ViewListDao) TmsDao.getViewListDao((TmsDao) carDao,
				TmsDao.TMS_DECT_CAR_INFO);

		List<TmsDetectInfo> entityList = new ArrayList<TmsDetectInfo>();
		// 将entit信息set到dao中
		TmsDetectInfoDto dto = new TmsDetectInfoDto();
		setDtoFromEntity(dto, entity);
		// 查询返回一个dto list
		List<TmsDetectInfoDto> dtoList = carDao.findCarInfoByCon(dto);
		// 将dtoList转换成entityList
		TmsDetectInfo ccEntity = null;
		int pp = 1;
		if (dtoList != null) {
			for (int i = 0; i < dtoList.size(); i++) {
				dto = (TmsDetectInfoDto) dtoList.get(i);
				ccEntity = new TmsDetectInfo();
				// 将dto数据重装到entity中
				setEntityFromDto(ccEntity, dto, pp, idao.getPageNo());
				entityList.add(ccEntity);
				pp++;
			}
		}

		setPagingInfo(idao);
		return entityList;
	}
	
	/**
	 * 根据车辆ID和状态查询车辆是否有检测信息
	 * 
	 * 直接返回一个检测ID
	 * 
	 * @return
	 * @throws TmsDaoException 
	 */
	public int findDetectInfoBySerialAndStatus(String serial) throws TmsDaoException
	{
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao.getInstance(TmsDao.TMS_DECT_CAR_INFO);		
		
		TmsDetectInfoDto dto = carInfoDao.getDetectinfoBySerialAndStatus(serial);
		//直接从dto中获取检测Id
		int cardetectID = 0;
		if(dto!=null)
		{
			cardetectID = dto.getCarDetectId();
		}
		return cardetectID;
	}
	
	/**
	 * 查看已完成的基本检测报告评分信息
	 */
	public TmsDetectInfo getDetectScore(String serial)throws TmsDaoException{
		TmsDetectInfoDao carInfoDao = (TmsDetectInfoDao) TmsDao.getInstance(TmsDao.TMS_DECT_CAR_INFO);		
		TmsDetectInfo detectinfo = null;
		TmsDetectInfoDto dto = carInfoDao.getDetectScore(serial);
		if(dto!=null)
		{
			detectinfo=new TmsDetectInfo();
			detectinfo.setTotalScore(dto.getTotalScore());
			detectinfo.setExternalScore(dto.getExternalScore());
			detectinfo.setInternalScore(dto.getInternalScore());
		}
		return detectinfo;
	}
	
	

	public int getSource() {
		return source;
	}

	public int getCounts() {
		return counts;
	}

	public void setCounts(int counts) {
		this.counts = counts;
	}

	public void setSource(int source) {
		this.source = source;
	}

	@Override
	public void save() throws TmsDaoException {
		// TODO Auto-generated method stub

	}

	public String getCarSerial() {
		return carSerial;
	}

	public void setCarSerial(String carSerial) {
		this.carSerial = carSerial;
	}

	public String getCarName() {
		return carName;
	}

	public void setCarName(String carName) {
		this.carName = carName;
	}

	public String getCarLicense() {
		return carLicense;
	}

	public void setCarLicense(String carLicense) {
		this.carLicense = carLicense;
	}

	public String getRegDate() {
		return regDate;
	}

	public void setRegDate(String regDate) {
		this.regDate = regDate;
	}

	public String getCarCheckInsur() {
		return carCheckInsur;
	}

	public void setCarCheckInsur(String carCheckInsur) {
		this.carCheckInsur = carCheckInsur;
	}

	public String getTrafficInsur() {
		return trafficInsur;
	}

	public void setTrafficInsur(String trafficInsur) {
		this.trafficInsur = trafficInsur;
	}

	public int getExhaust() {
		return exhaust;
	}

	public void setExhaust(int exhaust) {
		this.exhaust = exhaust;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public int getGearbox() {
		return gearbox;
	}

	public void setGearbox(int gearbox) {
		this.gearbox = gearbox;
	}

	public int getFuelDict() {
		return fuelDict;
	}

	public void setFuelDict(int fuelDict) {
		this.fuelDict = fuelDict;
	}

	public int getNature() {
		return nature;
	}

	public void setNature(int nature) {
		this.nature = nature;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}

	public int getUpdateUser() {
		return updateUser;
	}

	public void setUpdateUser(int updateUser) {
		this.updateUser = updateUser;
	}

	public int getMileage() {
		return mileage;
	}

	public void setMileage(int mileage) {
		this.mileage = mileage;
	}

	public int getTQcarNum() {
		return TQcarNum;
	}

	public void setTQcarNum(int tQcarNum) {
		TQcarNum = tQcarNum;
	}

	public int getTASNum() {
		return TASNum;
	}

	public void setTASNum(int tASNum) {
		TASNum = tASNum;
	}

	public String getTotalScore() {
		return totalScore;
	}

	public void setTotalScore(String totalScore) {
		this.totalScore = totalScore;
	}

	public String getExternalScore() {
		return externalScore;
	}

	public void setExternalScore(String externalScore) {
		this.externalScore = externalScore;
	}

	public String getInternalScore() {
		return internalScore;
	}

	public void setInternalScore(String internalScore) {
		this.internalScore = internalScore;
	}

	public String getAddModeName() {
		return addModeName;
	}

	public void setAddModeName(String addModeName) {
		this.addModeName = addModeName;
	}

	public int getChkModel() {
		return chkModel;
	}

	public void setChkModel(int chkModel) {
		this.chkModel = chkModel;
	}

	public int getCarDetectId() {
		return carDetectId;
	}

	public void setCarDetectId(int carDetectId) {
		this.carDetectId = carDetectId;
	}

	public int getSkylight() {
		return skylight;
	}

	public void setSkylight(int skylight) {
		this.skylight = skylight;
	}

	public int getLeatherSeats() {
		return leatherSeats;
	}

	public void setLeatherSeats(int leatherSeats) {
		this.leatherSeats = leatherSeats;
	}

	public int getAluminumRim() {
		return aluminumRim;
	}

	public void setAluminumRim(int aluminumRim) {
		this.aluminumRim = aluminumRim;
	}

	public int getGpsNavigation() {
		return gpsNavigation;
	}

	public void setGpsNavigation(int gpsNavigation) {
		this.gpsNavigation = gpsNavigation;
	}

	public int getAutoWindow() {
		return autoWindow;
	}

	public void setAutoWindow(int autoWindow) {
		this.autoWindow = autoWindow;
	}

	public int getAbs() {
		return abs;
	}

	public void setAbs(int abs) {
		this.abs = abs;
	}

	public int getSrsNumber() {
		return srsNumber;
	}

	public void setSrsNumber(int srsNumber) {
		this.srsNumber = srsNumber;
	}

	public int getFourWheelDrive() {
		return fourWheelDrive;
	}

	public void setFourWheelDrive(int fourWheelDrive) {
		this.fourWheelDrive = fourWheelDrive;
	}

	public int getTroubleCar() {
		return troubleCar;
	}

	public void setTroubleCar(int troubleCar) {
		this.troubleCar = troubleCar;
	}

	public String getCarDescribe() {
		return carDescribe;
	}

	public void setCarDescribe(String carDescribe) {
		this.carDescribe = carDescribe;
	}

	public String getStartSerial() {
		return startSerial;
	}

	public void setStartSerial(String startSerial) {
		this.startSerial = startSerial;
	}

	public String getEndSerial() {
		return endSerial;
	}

	public void setEndSerial(String endSerial) {
		this.endSerial = endSerial;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	public int getSeeBsflag() {
		return seeBsflag;
	}

	public void setSeeBsflag(int seeBsflag) {
		this.seeBsflag = seeBsflag;
	}

	public int getScopeNum() {
		return scopeNum;
	}

	public void setScopeNum(int scopeNum) {
		this.scopeNum = scopeNum;
	}

	public Timestamp getCheckTime() {
		return checkTime;
	}

	public void setCheckTime(Timestamp checkTime) {
		this.checkTime = checkTime;
	}

	public int getBidStatus() {
		return bidStatus;
	}

	public void setBidStatus(int bidStatus) {
		this.bidStatus = bidStatus;
	}

}
